<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>分配项目</title>
	<meta name="decorator" content="default"/>
	<link href="${ctxStatic}/font-awesome/css/font-awesome.min.css" type="text/css" rel="stylesheet" />
	<style type="text/css">
		.assign-box{            
        }
        .assign-info{
            float: left;
            width: 225px;
            margin: 10px;
            border: 1px solid #e3e4e8;
            border-radius: 6px;
            position: relative;
        } 
        .assign-name{
            border-bottom: 1px solid #eceef1;
            padding: 15px 20px;
            color: #777c85;
            font-size: 12px;
        }
        .assign-name b{
            font-size: 14px;
            color: #494c53;
        }
        .assign-tel{
            padding: 2px 20px;
            background: #fafcfd;
        }            
        .assign-tel p{
            padding:6px 0;
            font-size: 14px; 
            border-bottom: 1px solid #eceef1;
            color: #adb2bf;
        }
        .assign-edit{
        	position: absolute;
		    top: 10px;
		    right: 10px;
		    cursor: pointer;
		    color: #adb2bf;
        }
        .assign-give{
        	position: absolute;
		    top: 10px;
		    right: 50px;
		    cursor: pointer;
		    color: #adb2bf;
        }
	</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/pro/project/">项目列表</a></li>
		<li class="active"><a href="${ctx}/pro/project/assign?id=${project.id}"><shiro:hasPermission name="pro:project:edit">人员分配</shiro:hasPermission><shiro:lacksPermission name="sys:role:edit">人员列表</shiro:lacksPermission></a></li>
	</ul>
	<div class="container-fluid breadcrumb">
		<div class="row-fluid">
			<span class="span4">项目名称: <b>${project.name}</b></span>
			<span class="span4">负责人: ${project.manager.name}</span>
		</div>
		<div class="row-fluid">
			<span class="span4">开始时间: <fmt:formatDate value="${project.startTime}" pattern="yyyy-MM-dd"/></span>
			<span class="span4">结束时间: <fmt:formatDate value="${project.endTime}" pattern="yyyy-MM-dd"/></span>
		</div>
	</div>
	<sys:message content="${message}"/>
	<div class="breadcrumb">
		<form id="assignRoleForm" action="${ctx}/pro/project/assignrole" method="post" class="hide">
			<input type="hidden" name="id" value="${project.id}"/>
			<input id="idsArr" type="hidden" name="idsArr" value=""/>
		</form>
		<form id="assignAuthForm" action="${ctx}/pro/project/updateCode" method="post" class="hide">
			<input type="hidden" name="projectId" value="${project.id}"/>
			<input id="userId" type="hidden" name="userId" value=""/>
			<input id="code" type="hidden" name="code" value=""/>
		</form>
		<input id="assignButton" class="btn btn-primary" type="submit" value="分配人员"/>
		<script type="text/javascript">
			$("#assignButton").click(function(){
				top.$.jBox.open("iframe:${ctx}/pro/project/usertoproject?id=${project.id}", "分配人员",810,$(top.document).height()-240,{
					buttons:{"确定分配":"ok", "清除已选":"clear", "关闭":true}, bottomText:"通过选择部门，然后为列出的人员分配项目。",submit:function(v, h, f){
						var pre_ids = h.find("iframe")[0].contentWindow.pre_ids;
						var ids = h.find("iframe")[0].contentWindow.ids;
						//nodes = selectedTree.getSelectedNodes();
						if (v=="ok"){
							// 删除''的元素
							if(ids[0]==''){
								ids.shift();
								pre_ids.shift();
							}
							if(pre_ids.sort().toString() == ids.sort().toString()){
								top.$.jBox.tip("未给项目【${project.name}】分配新成员！", 'info');
								return false;
							};
					    	// 执行保存
					    	loading('正在提交，请稍等...');
					    	var idsArr = "";
					    	for (var i = 0; i<ids.length; i++) {
					    		idsArr = (idsArr + ids[i]) + (((i + 1)== ids.length) ? '':',');
					    	}
					    	$('#idsArr').val(idsArr);
					    	$('#assignRoleForm').submit();
					    	return true;
						} else if (v=="clear"){
							h.find("iframe")[0].contentWindow.clearAssign();
							return false;
		                }
					}, loaded:function(h){
						$(".jbox-content", top.document).css("overflow-y","hidden");
					}
				});
			});
			function assignAuth(userId,projectId){
				var url = "${ctx}/pro/project/assignAuth?userId="+userId+"&projectId="+projectId;
				top.$.jBox.open("iframe:"+url, "分配权限",810,$(top.document).height()-240,{
                    buttons:{"确定分配":"ok", "关闭":true}, bottomText:"为列出的人员分配项目权限。",submit:function(v, h, f){
                        var code;
                        if (v=="ok"){
                        	// 执行保存
                            loading('正在提交，请稍等...');
                        	h.find("iframe")[0].contentWindow.cacl();
                        	code = h.find("iframe")[0].contentWindow.code;
                        	$("#code").val(code);
                        	$("#userId").val(userId);
					    	$('#assignAuthForm').submit();
                            return true;
                        }
                    }, loaded:function(h){
                        $(".jbox-content", top.document).css("overflow-y","hidden");
                    }
                });
			}
		</script>
	</div>
	<div class="box box-bottom"> 
        <div class="assign-box">
        	<c:forEach items="${userList}" var="user">                
	            <div class="assign-info">
	               <div class="assign-name">
	                  <b>${user.name}</b><br>
	                  归属公司：${user.company.name}<br>
	                  归属部门：${user.office.name}<br>
	                  登录名：${user.loginName}<br>	                  
	               </div>
	               <div class="assign-tel">
	                   <p>
	                      <span class="fa fa-phone-square"></span> ${user.phone}
	                   </p>
	                   <p>
	                      <span class="fa fa-phone-square"></span> ${user.mobile}
	                   </p>
	               </div>
	               <shiro:hasPermission name="sys:role:edit">
				    <a class="fa fa-trash-o assign-edit" href="${ctx}/pro/project/outProject?userId=${user.id}&projectId=${project.id}" 
					onclick="return confirmx('确认要将用户<b>[${user.name}]</b>从<b>[${project.name}]</b>项目中移除吗？', this.href)">移除</a>
			       </shiro:hasPermission>
			       <c:if test="${fns:getUser().id == project.manager.id}">
				    <a id="assignAuth" onclick="assignAuth('${user.id}','${project.id}');" class="fa fa-trash-o assign-give" href="javascript:void(0);" 
					>授权</a>
				    </c:if>
	            </div>
            </c:forEach>
        </div>
    </div>
	<!-- <table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr><th>归属公司</th><th>归属部门</th><th>登录名</th><th>姓名</th><th>电话</th><th>手机</th><shiro:hasPermission name="sys:user:edit"><th>操作</th></shiro:hasPermission></tr></thead>
		<tbody>
		<c:forEach items="${userList}" var="user">
			<tr>
				<td>${user.company.name}</td>
				<td>${user.office.name}</td>
				<td>${user.loginName}</td>
				<td>${user.name}</td>
				<td>${user.phone}</td>
				<td>${user.mobile}</td>
				<shiro:hasPermission name="sys:role:edit"><td>
					<a href="${ctx}/pro/project/outProject?userId=${user.id}&projectId=${project.id}" 
						onclick="return confirmx('确认要将用户<b>[${user.name}]</b>从<b>[${project.name}]</b>角色中移除吗？', this.href)">移除</a>
				</td></shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table> -->
</body>
</html>
